package com.neegix.organization.post.application.service.impl;

import com.neegix.application.command.BaseService;
import com.neegix.exception.BusinessRuntimeException;
import com.neegix.organization.post.application.cqrs.command.BatchDeletePostCommand;
import com.neegix.organization.post.application.cqrs.command.NewPostCommand;
import com.neegix.organization.post.application.cqrs.command.UpdatePostCommand;
import com.neegix.organization.post.application.cqrs.query.PostQueryRepository;
import com.neegix.organization.post.application.service.PostService;
import com.neegix.organization.post.domain.entity.PostEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

 /**
  * This file is auto-generated by nebula-framework-generator.
  * The auto-generation plugin was developed using IntelliJ IDEA Community Edition.
  * Thanks to JetBrains for their outstanding contributions to the developer community.
  * <p>
  * The code generated by this tool is owned by the user of the tool.
  * The tool itself is copyrighted by <a href="https://www.neegix.com">https://www.neegix.com</a>.
  *
  * @author <a href="https://www.neegix.com">https://www.neegix.com</a>
  * @version 1.0.0
  * @since 2024-11-25 11:27:14
  */

@Service
public class PostServiceImpl extends BaseService implements PostService{
    @Autowired
    private PostQueryRepository postQueryRepository;

    @Override
    public Void createPost(PostEntity postEntity) {
        return commandInvoker.execute(new NewPostCommand(postEntity));
    }

    @Override
    public Void modifyPost(PostEntity postEntity) {
        return commandInvoker.execute(new UpdatePostCommand(postEntity));
    }

    @Override
    public Void removePost(List<Long> ids) {
        Integer count = postQueryRepository.selectCount(ids);
        if (count.equals(0)){
            throw new BusinessRuntimeException("要删除的记录不存在！");
        }
        return commandInvoker.execute(new BatchDeletePostCommand(ids));
    }
}
